pip install geopandas
Collecting geopandas
Downloading geopandas-0.10.2-py2.py3-none-any.whl (1.0 MB)
|████████████████████████████████| 1.0 MB 2.9 MB/s eta 0:00:01
Collecting fiona>=1.8
Downloading Fiona-1.8.21-cp38-cp38-macosx_10_10_x86_64.whl (18.5 MB)
|████████████████████████████████| 18.5 MB 4.9 MB/s eta 0:00:011 |██▍ | 1.4 MB 24.7 MB/s eta 0:00:01
Collecting pyproj>=2.2.0
Downloading pyproj-3.3.0-cp38-cp38-macosx_10_9_x86_64.whl (7.7 MB)
|████████████████████████████████| 7.7 MB 14.3 MB/s eta 0:00:01
Requirement already satisfied: pandas>=0.25.0 in ./opt/anaconda3/lib/python3.8/site-packages (from geopandas) (1.3.4)
Collecting shapely>=1.6
Downloading Shapely-1.8.1.post1-cp38-cp38-macosx_10_9_x86_64.whl (1.2 MB)
|████████████████████████████████| 1.2 MB 28.3 MB/s eta 0:00:01
Requirement already satisfied: click>=4.0 in ./opt/anaconda3/lib/python3.8/site-packages (from fiona>=1.8->geopandas) (8.0.3)
Requirement already satisfied: six>=1.7 in ./opt/anaconda3/lib/python3.8/site-packages (from fiona>=1.8->geopandas) (1.16.0)
Requirement already satisfied: certifi in ./opt/anaconda3/lib/python3.8/site-packages (from fiona>=1.8->geopandas) (2021.10.8)
Collecting cligj>=0.5
Downloading cligj-0.7.2-py3-none-any.whl (7.1 kB)
Collecting click-plugins>=1.0
Downloading click_plugins-1.1.1-py2.py3-none-any.whl (7.5 kB)
Requirement already satisfied: setuptools in ./opt/anaconda3/lib/python3.8/site-packages (from fiona>=1.8->geopandas) (58.0.4)
Requirement already satisfied: attrs>=17 in ./opt/anaconda3/lib/python3.8/site-packages (from fiona>=1.8->geopandas) (21.2.0)
Collecting munch
Downloading munch-2.5.0-py2.py3-none-any.whl (10 kB)
Requirement already satisfied: python-dateutil>=2.7.3 in ./opt/anaconda3/lib/python3.8/site-packages (from pandas>=0.25.0->geopandas) (2.8.2)
Requirement already satisfied: pytz>=2017.3 in ./opt/anaconda3/lib/python3.8/site-packages (from pandas>=0.25.0->geopandas) (2021.3)
Requirement already satisfied: numpy>=1.17.3 in ./opt/anaconda3/lib/python3.8/site-packages (from pandas>=0.25.0->geopandas) (1.20.3)
Installing collected packages: munch, cligj, click-plugins, shapely, pyproj, fiona, geopandas
Successfully installed click-plugins-1.1.1 cligj-0.7.2 fiona-1.8.21 geopandas-0.10.2 munch-2.5.0 pyproj-3.3.0 shapely-1.8.1.post1
Note: you may need to restart the kernel to use updated packages.
import os
import pandas as pd
import geopandas as gdp
import matplotlib.pyplot as plt
df = pd.read_csv('/Users/talatayebi/seasonal_disparities_20th_century.csv')
past = df[df.YEAR == 2000]
present = df[df.YEAR == 2021]
past = past[past.Season == 'Winter']
past.head()
| FIPSCode | YEAR | Season | TEMPERATURE_MA | TEMPERATURE_DEVIATION_STDDEV | TEMPERATURE_INDEX | PRECIPITATION_MA | PRECIPITATION_DEVIATION_STDDEV | PRECIPITATION_INDEX | |
|---|---|---|---|---|---|---|---|---|---|
| 27928 | 6019 | 2000 | Winter | 43.6 | 1.578718 | Normal | 0.25 | -1.126718 | Normal |
| 27930 | 6063 | 2000 | Winter | 35.0 | 0.782191 | Normal | 1.53 | -1.029810 | Normal |
| 27932 | 6075 | 2000 | Winter | 51.7 | 1.167268 | Normal | 0.86 | -1.210542 | Normal |
| 27933 | 6077 | 2000 | Winter | 47.5 | 0.609165 | Normal | 0.40 | -1.197096 | Normal |
| 27934 | 6087 | 2000 | Winter | 51.0 | 1.330833 | Normal | 1.03 | -1.119267 | Normal |
present = present[present.Season == 'Winter']
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
counties = json.load(response)
pip install plotly
Collecting plotly
Downloading plotly-5.6.0-py2.py3-none-any.whl (27.7 MB)
|████████████████████████████████| 27.7 MB 3.7 MB/s eta 0:00:011
Collecting tenacity>=6.2.0
Downloading tenacity-8.0.1-py3-none-any.whl (24 kB)
Requirement already satisfied: six in ./opt/anaconda3/lib/python3.8/site-packages (from plotly) (1.16.0)
Installing collected packages: tenacity, plotly
Successfully installed plotly-5.6.0 tenacity-8.0.1
Note: you may need to restart the kernel to use updated packages.
import plotly.express as px
fig = px.choropleth(past, geojson=counties, locations='FIPSCode', color='PRECIPITATION_MA',
color_continuous_scale="Viridis",
range_color=(0, 12),
scope="usa",
labels={'PRECIPITATION_MA':'Precipitation(in.)', 'FIPSCode':'County Code'}
)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
fig = px.choropleth(present, geojson=counties, locations='FIPSCode', color='PRECIPITATION_MA',
color_continuous_scale="Viridis",
range_color=(0, 12),
scope="usa",
labels={'PRECIPITATION_MA':'Precipitation(in.)', 'FIPSCode': 'County Code'}
)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()